<template>
  <div class="asideContianer">

    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
             :collapse="isCollapse" background-color="rgb(50,65,87)" text-color="#fff" active-text-color="#ffd04b">

      <h3>{{isCollapse ? 'CRM' : 'CRM系统'}}</h3>
      <!-- 没有二级菜单 -->
      <el-menu-item v-for="item in noChildren" :key="item.name" :index="item.name" @click="clickMenu(item)">
        <i :class="`el-icon-${item.icon}`"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>
      <!-- 有二级菜单 -->
      <el-submenu v-for="item in hasChildren" :key="item.name" :index="item.name">
        <template slot="title">
          <i :class="`el-icon-${item.icon}`"></i>
          <span slot="title">{{ item.label }}</span>
        </template>

        <el-menu-item-group v-for="subItem in item.children" :key="subItem.name">
          <el-menu-item :index="subItem.name" @click="clickMenu(subItem)">{{ subItem.label }}</el-menu-item>
        </el-menu-item-group>
<!--        <el-menu-item index="4">-->
<!--          <i class="el-icon-setting"></i>-->
<!--          <span slot="title">设置</span>-->
<!--        </el-menu-item>-->
      </el-submenu>

    </el-menu>
  </div>
</template>

<style lang="less" scoped>

.el-menu {
  height: 100vh;
  border-right: none;

  h3 {
    color: #fff;
    text-align: center;
    line-height: 48px;
    font-size: 22px;
    font-weight: 400;
  }
}
</style>

<script>
export default {
  name: 'Aside',
  data() {
    return {
      // isCollapse: false,
      menuData: [
        {
          path: '/',
          name: 'main',
          label: '首页',
          icon: 's-home',
          url: 'Home/Home'
        },
        {
          label: '客户管理',
          icon: 'user',
          name: 'customer',
          children: [
            {
              path: '/Consumer',
              name: 'customerList',
              label: '客户列表',
              icon: 'setting',
              url: 'customer/customerList'
            },
          ]
        },
        {
          label: '订单管理',
          icon: 's-order',
          name: 'order',
          children: [
            {
              path: '/AllOrder',
              name: 'allOrder',
              label: '全部订单',
              icon: 'setting',
              url: 'order/allOrder'
            },
          ]
        },
        {
          label: '库存管理',
          icon: 's-order',
          name: 'stock',
          children: [
            {
              path: '/stock',
              name: 'Allstock',
              label: '库存列表',
              icon: 'setting',
              url: 'stock/Allstock'
            },
          ]
        },
        {
          label: '业务管理',
          icon: 's-order',
          name: 'business',
          children: [
            {
              path: '/Business',
              name: 'business',
              label: '业务',
              icon: 'setting',
              url: 'business/AllBusiness'
            },
          ]
        },
        {
          label: '系统管理',
          icon: 'user',
          name: 'system',
          children: [
            {
              path: '/User',
              name: 'user',
              label: '员工管理',
              icon: 'setting',
              url: 'sys/user'
            },
            {
              path: '/Role',
              name: 'role',
              label: '角色管理',
              icon: 'setting',
              url: 'sys/role'
            },
            {
              path: 'Region',
              name: 'region',
              label: '区域管理',
              icon: 'setting',
              url: 'sys/region'
            },
            {
              path: 'Material',
              name: 'material',
              label: '设备管理',
              icon : 'setting',
              url: 'sys/material'
            }
          ]
        }
      ],
    };
  },
  methods: {
    handleOpen(key, keyPath) {

    },
    handleClose(key, keyPath) {

    },
    clickMenu(item) {
      // console.log(item)
      if (this.$route.path != item.path && !(this.$route.path === '/FirstPage' && item.path === '/')) {
        this.$router.push(item.path)
      }
    }
  }, computed: {
    hasChildren() {
      //过滤所有的有二级菜单的数据
      return this.menuData.filter(item => item.children)
    },
    noChildren() {
      //过滤只有一级菜单的数据
      return this.menuData.filter(item => !item.children)
    },
    isCollapse(){
      return this.$store.state.tab.isCollapse
    }
  }
}
</script>
